<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="1000" destroy-on-close @closed="$emit('closed')" :align-center="true">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="110px" label-position="right">
			<div class="sketch_content">
                <el-row :gutter="1">
                    <el-row :gutter="1">
                        <el-col :span="8">
                            <el-form-item label="针种" prop="needle_seed">
                                <el-select v-model="form.needle_seed" filterable multiple placeholder="请选择针种" style="width:100%" collapse-tags clearable>
                                    <el-option v-for="item in needleList" :key="item.id" :label="item.title" :value="item.id" />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="织机时间" prop="loom_time">
                                <el-input v-model="form.loom_time" placeholder="请输入织机时间" clearable></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="完成时间" prop="sign_time">
                                <el-date-picker v-model="sign_time" style="width:100%" type="date" placeholder="请选择时间" disabled />
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-row>
                <el-form-item label="工序信息" prop="process_data">
                    <sc-form-table ref="table" v-model="form.process_data" placeholder="暂无数据" hideAdd show-summary>
                        <el-table-column label="一级工序" align="center">
                            <template #default="scope">
                            <div>{{scope.row.process_title}}</div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="price" label="报价金额" align="center">
                            <template #default="scope">
                                <div>
                                    {{scope.row.price}}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="pricing_price" label="下单核价" align="center">
                            <template #default="scope">
                                <el-input v-model="scope.row.pricing_price" placeholder="请输入下单核价"></el-input>
                            </template>
                        </el-table-column>
                    </sc-form-table>
                </el-form-item>
			</div>
		</el-form>
		<template #footer>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">完 成</el-button>
			<el-button @click="visible=false" >取 消</el-button>
		</template>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '添加客户',
					edit: '编辑客户',
					over: '修改价格',
					show: '价格查看',
				},
				visible: false,
				isSaveing: false,
                grade:"潜力",
				//表单数据
				form: {
					id:"",
                    needle_seed:"",
                    loom_time:"",
                    process_data:[]
				},
                sign_time:"",
				//验证规则
				rules: {
                    comment: [
						{required: true, message: '请输入工厂报价'}
					],
				},
                needleList:[], //针
			}
		},
		mounted() {
            this.getNeedle()
		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						this.isSaveing = true;
						var res  = [];
						res = await this.$API.develop.edition.completeModify.post(this.form);
						this.isSaveing = false;
						if(res.code == 1){
							this.$emit('success', this.form, this.mode)
							this.visible = false;
							this.$message.success("操作成功")
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}else{
						return false;
					}
				})
			},
			//表单注入数据
			async setData(data){
                this.form.id = data.id
                var res = await this.$API.develop.edition.detail.get({id:data.id});
                this.form.needle_seed = res.data.goods.needle_seed
                this.form.loom_time = res.data.loom_time
                this.sign_time = res.data.sign_time
                let a = []
                res.data.patternCompleted.map(item=>{
                    a.push({
                        id:item.id,
                        process_id:item.process_id,
                        process_title:item.title,
                        price:item.price,
                        pricing_price:item.pricing,
                        
                    })
                })
                this.form.process_data = a
			},
            async getNeedle(){
                var res = await this.$API.all.needle.get();
                this.needleList = res.data;
            },
		}
	}
</script>

<style lang="scss">
.el-form-item--default{
    align-items: center;
}
</style>
